/*
 * @Author: Evan-lian
 * @Date: 2023-12-25 15:31:33
 * @LastEditors: Evan-lian
 * @LastEditTime: 2023-12-25 21:36:38
 * @Description: 
 */
import axios from 'axios';
import NProgress from 'nprogress';
import { message } from 'antd';

//不提示转圈
NProgress.settings.showSpinner = false;
const request = axios.create({
    baseURL: 'https://console-mock.apipost.cn/app/mock/project/8a8dba66-4ee2-47d2-a89e-68769b9bc91b/',
    timeout: 5000
})
request.interceptors.request.use(config => {
    let token = sessionStorage.getItem('token');
    NProgress.start();
    if (token) {
        config.headers['Authorization'] = `Bearer${token}`
    }
    return config
})
request.interceptors.response.use(
    (res) => {
        NProgress.done();
        if(res.status!==200){
            if (res.status === 401) {
                message.info('没有权限')
            } else if (res.status === 500 || res.status === 505) {
                message.info('服务器错误')
            } else if (res.status === 404) {
                message.info('404请求地址找不到')
            } else {
                message.info('请求错误')
            }

        }
        return res;
       
      
    },
    (err) => {
        NProgress.done();
        message.info('请求错误')
        console.log(err)
        return err
    }
)
export default request